package xps.and.uudaijia.userclient.view.activity;

import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.jude.utils.JUtils;
import com.zhy.autolayout.AutoRelativeLayout;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import jp.wasabeef.glide.transformations.CropCircleTransformation;
import rx.Subscriber;
import xps.and.uudaijia.userclient.R;
import xps.and.uudaijia.userclient.data.baen.CodeBean;
import xps.and.uudaijia.userclient.data.net.UserNetWorks;
import xps.and.uudaijia.userclient.view.RatingBar;
import xps.and.uudaijia.userclient.view.base.BaseActivity;

/**
 * Created by XPS on 2017/7/21.
 */

public class CommentDriverActivity extends BaseActivity {
    @BindView(R.id.actionbar_iv_back)
    ImageView actionbarIvBack;
    @BindView(R.id.actionbar_tv_title)
    TextView actionbarTvTitle;
    @BindView(R.id.actionbar_tv_right)
    TextView actionbarTvRight;
    @BindView(R.id.v_gap_line)
    View vGapLine;
    @BindView(R.id.actionbar_al)
    AutoRelativeLayout actionbarAl;
    @BindView(R.id.iv_driver_head)
    ImageView ivDriverHead;
    @BindView(R.id.tv_driver_name)
    TextView tvDriverName;
    @BindView(R.id.et_reason)
    EditText etReason;
    @BindView(R.id.bt_confirm)
    Button btConfirm;
    String orderId = "";
    @BindView(R.id.business_RatingBar)
    RatingBar businessRatingBar;
    String XX = "1";
    String driverHeadImg;
    String driverName;

    @Override
    protected int getLayout() {
        return R.layout.activity_comment_driver;
    }

    @Override
    protected void setData() {
    }

    @Override
    protected void init() {
        ButterKnife.bind(this);
        Intent i = getIntent();
        orderId = i.getStringExtra("orderId");
        driverName = i.getStringExtra("driverName");
        driverHeadImg = i.getStringExtra("driverHeadImg");

        Glide.with(CommentDriverActivity.this).load(driverHeadImg)
                .placeholder(R.mipmap.logo)
                .bitmapTransform(new CropCircleTransformation(CommentDriverActivity.this))
                .into(ivDriverHead);
        tvDriverName.setText(driverName + "师傅");
        actionbarTvTitle.setText("订单评论");
        businessRatingBar.setClickable(true);
        businessRatingBar.setStar(5f);

        businessRatingBar.setOnRatingChangeListener((ratingCount) -> {
            XX = Math.round(ratingCount) + "";
        });
    }

    @OnClick({R.id.actionbar_iv_back, R.id.bt_confirm})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.actionbar_iv_back:
                finish();
                break;
            case R.id.bt_confirm:
                getPL();
                break;
        }
    }

    void getPL() {
        UserNetWorks.getPL(orderId, XX, etReason.getText().toString(), new Subscriber<CodeBean>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                e.printStackTrace();
            }

            @Override
            public void onNext(CodeBean codeBean) {
                if (codeBean.getReturn_code().equals("SUCCESS")) {
                    JUtils.Toast(codeBean.getReturn_msg());
                    finish();
                } else if (codeBean.getReturn_code().equals("FAIL")) {
                    JUtils.Toast(codeBean.getReturn_msg());
                }
            }
        });
    }
}
